#coding=utf-8
__author__ = 'Meteor'

import subprocess,os,time
import setings
from common.log import logger

class Option:
    def __init__(self):
        # 记录mock server启动的pid，关闭用到
        self.pid = None
        # 用来记录mock server是否已经被启动，默认未启动
        self.start = False
    def start_mock(self):
        # 如果调用了mock server启动方法，则将start修改为True，表示已经启动
        self.start = True
        mock_file = os.path.join(setings.BASE,'mock','mock_server.py')
        logger.info('启动mock server')
        # 启动mock server
        s = subprocess.Popen('python %s' %mock_file)
        time.sleep(5)
        self.pid = s.pid

    def stop(self):
        if self.pid:
            os.popen('taskkill /F /PID %d' %self.pid)
            logger.info('关闭mock server')
        else:
            logger.error('mock server 未启动，不能关闭')




mock = Option()
